#ifndef __CPPDLLIST_H_
#define __CPPDLLIST_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ElementType void*
#define INITDLLIST(list)  DLList list;InitDLList(&list);

//结点类
class DoubleLinkNode
{
public:
    DoubleLinkNode(ElementType element);
    ~DoubleLinkNode();
    friend class DoubleLinkList; //声明友元类
    friend class TreeNode;
private:
    ElementType data;  //数据域
    DoubleLinkNode* next; //后驱节点指针
    DoubleLinkNode* prev; //前驱节点指针
};
using DLNode = DoubleLinkNode;

/*——————————————————————————————————————————————————————————————————————————————————————————————*/

//链表类
class DoubleLinkList
{
public:
    DoubleLinkList();
    DoubleLinkList(void(*CLearptr)(ElementType));
    ~DoubleLinkList();
    void InsertTail_DLList(ElementType element);//尾插
    void InsertHead_DLList(ElementType element);//头插
    void InsertByIndex_DLList(ElementType element,int index);//按位置插
    void Travel_DLList(void(*funcptr)(ElementType)); //遍历
    void RemoveByIndex_DLList(int index); //按位置删
    void RemoveByElement_DLList(ElementType element,bool(*opreptr)(ElementType,ElementType)); //按值删
    ElementType* SearchByIndex_DLList(int index); //按位置查找
    //按值查找
    DoubleLinkList SearchByElement_DLList(ElementType element,bool(*opreptr)(ElementType,ElementType));
    void DLListSort(bool(*funcptr)(ElementType,ElementType));//快速排序
    DoubleLinkNode* GetListHead();
private:
    DLNode* head;  //头指针
    DLNode* tail;  //尾指针
    void(*CLearptr)(ElementType);//自定义的clear函数指针
    int len;
    void FastSort_DLList(DLNode* start,DLNode* end,bool(*funcptr)(ElementType,ElementType));
};



#endif